package com.jhc.common.core.web.page;


import com.jhc.common.core.enums.OrderType;
import com.jhc.common.core.utils.Null;
import com.jhc.common.core.utils.StringUtils;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.List;

/**
 * 分页请求参数
 *
 * @author
 */
@Accessors(chain = true)
@Setter
public class PageDomain {
    /**
     * 当前记录起始索引
     */
    @Getter
    private Integer pageNum;

    /**
     * 每页显示记录数
     */
    @Getter
    private Integer pageSize;

    /**
     * 排序列
     */
    private String orderByColumn;

    /**
     * 排序的方向desc或者asc
     */
    private OrderType orderType = OrderType.ASC;

    private List<PageFilter> filters;


    public String getOrderBy() {
        if (StringUtils.isEmpty(orderByColumn)) {
            return "";
        }
        return StringUtils.toUnderScoreCase(orderByColumn) + " " + orderType.getValue();
    }



    public String getWhere() {
        return PageFilter.buildWhere(this.filters);
    }

    public boolean validPageParam(){
        return Null.allNotEmpty(this.pageNum, this.pageSize);
    }
}
